package cn.topevery.garden.framework.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 描述 日期工具类
 *
 * @author wenzhao.lin
 * @created 2021 -03-26 10:13:34
 */
public class DateUtils {

    /**
     * 描述 获取今日起始时间.
     *
     * @return the today start time
     * @author wenzhao.lin
     * @created 2021 -03-26 10:13:34
     */
    public static Date getTodayStartTime() {
        Calendar startTime = Calendar.getInstance();
        startTime.set(Calendar.HOUR, 0);
        startTime.set(Calendar.MINUTE, 0);
        startTime.set(Calendar.SECOND, 0);
        startTime.set(Calendar.MILLISECOND, 0);
        return startTime.getTime();
    }


    /**
     * 描述 获取今日结束时间
     *
     * @return the today end time
     * @author wenzhao.lin
     * @created 2021 -03-26 10:13:34
     */
    public static Date getTodayEndTime() {
        Calendar endTime = Calendar.getInstance();
        endTime.set(Calendar.HOUR, 23);
        endTime.set(Calendar.MINUTE, 59);
        endTime.set(Calendar.SECOND, 59);
        endTime.set(Calendar.MILLISECOND, 999);
        return endTime.getTime();
    }

    /**
     * 描述 获取本年的第一天.
     *
     * @return the date
     * @author wenzhao.lin
     * @created 2021 -03-26 17:30:36 Get curr year first date.
     */
    public static Date getCurrYearFirst() {
        Calendar currCal = Calendar.getInstance();
        int currentYear = currCal.get(Calendar.YEAR);
        return getYearFirst(currentYear);
    }


    /**
     * 描述 create.
     *
     * @param year the year
     * @return the date
     * @author wenzhao.lin
     * @created 2021 -03-26 17:37:08 Get year first date.
     */
    public static Date getYearFirst(int year) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, year);
        Date currYearFirst = calendar.getTime();
        return currYearFirst;
    }

    /**
     * 描述 获取当年的最后一天.
     *
     * @return the date
     * @author wenzhao.lin
     * @created 2021 -03-26 17:30:36 Get curr year last date.
     */
    public static Date getCurrYearLast() {
        Calendar currCal = Calendar.getInstance();
        int currentYear = currCal.get(Calendar.YEAR);
        return getYearLast(currentYear);
    }

    /**
     * 描述 create.
     *
     * @param year the year
     * @return the date
     * @author wenzhao.lin
     * @created 2021 -03-26 17:37:12 Get year last date.
     */
    public static Date getYearLast(int year) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, year);
        calendar.roll(Calendar.DAY_OF_YEAR, -1);
        Date currYearLast = calendar.getTime();
        return currYearLast;
    }

    public static String DateFormatFull(String dateStr) throws ParseException {
        Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(dateStr);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
        return dateFormat.format(date);
    }
}
